package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import negocio.Sala;
import negocio.SalaControlador;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class SalasCrear extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private Salas padreSalas;

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AulasCrear frame = new AulasCrear();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});And
	}

	/**
	 * Create the frame.
	 */
	public SalasCrear(Salas padreSalas) {
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e){
				textField.setText("");
				textField_1.setText("");
				textField_2.setText("");
				padreSalas.nullSalasCrear();
				dispose();
			}
		});
		this.padreSalas=padreSalas;
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setTitle("Crear sala");
		setBounds(100, 100, 274, 166);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNumeroDeAula = new JLabel("Numero de aula");
		lblNumeroDeAula.setBounds(10, 11, 81, 14);
		contentPane.add(lblNumeroDeAula);
		
		JLabel lblDescripci = new JLabel("Cantidad de computadoras");
		lblDescripci.setBounds(10, 36, 140, 14);
		contentPane.add(lblDescripci);
		
		JLabel lblCapacidadMaxima = new JLabel("Capacidad maxima");
		lblCapacidadMaxima.setBounds(10, 61, 100, 14);
		contentPane.add(lblCapacidadMaxima);
		
		textField = new JTextField();
		textField.setBounds(160, 33, 86, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setBounds(160, 8, 86, 20);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setBounds(160, 58, 86, 20);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				textField.setText("");
				textField_1.setText("");
				textField_2.setText("");
				padreSalas.nullSalasCrear();
				dispose();
			}
		});
		btnCancelar.setBounds(157, 94, 89, 23);
		contentPane.add(btnCancelar);
		
		JButton btnCreaSalar = new JButton("Crear sala");
		btnCreaSalar.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				Integer numeroSala= Integer.parseInt(textField_1.getText());
				Integer cantPcs= Integer.parseInt(textField.getText());
				Integer capMax= Integer.parseInt(textField_2.getText());
				SalaControlador.guardar(new Sala(numeroSala, capMax, cantPcs));
				padreSalas.llenarTabla();
				textField.setText("");
				textField_1.setText("");
				textField_2.setText("");
				dispose();
			}
		});
		btnCreaSalar.setBounds(58, 94, 89, 23);
		contentPane.add(btnCreaSalar);
	}
}
